#include "StdAfx.h"
#include "resource.h"
#include "World.h"

World sWorld;
LRESULT CALLBACK DialogProc(HWND ,UINT,WPARAM,LPARAM);
int WINAPI WinMain(	HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR	lpCmdLine,int nCmdShow)
{		
	HWND hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_SERVER), NULL, (DLGPROC)DialogProc);
	ShowWindow(hwnd, SW_SHOW);      
	UpdateWindow(hwnd);
	MSG msg;
	while(GetMessage(&msg, NULL, 0, 0))         
	{   
		if(!IsDialogMessage(hwnd, &msg))  
		{  
			TranslateMessage(&msg);  
			DispatchMessage(&msg);    
		} 
	}
  
	return	0;
}
LRESULT CALLBACK DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)         
{    
	switch(uMsg)      
	{      
	case WM_INITDIALOG: 
		SendMessage(hWnd, WM_SETICON, IDI_SMALL, 0);
		SetWindowPos(hWnd,NULL,500,200,0,0,SWP_NOSIZE);
		sWorld.Init(GetDlgItem(hWnd, IDC_EDIT));
		break;
 	case WM_COMMAND:
 		if(LOWORD(wParam) == IDCANCEL)       
 		{       
 			DestroyWindow(hWnd);                
 			return TRUE;      
 		}                 
 		break;
	case WM_DESTROY: 
		sWorld.Stop();   
		PostQuitMessage(0);      
		break;  
	}      
	return FALSE;  
}